home *** CD-ROM | disk | FTP | other *** search
- ' SHAPES.BAS
- ' This program displays a shape filled with your favorite character.
-
- ' declare constants used as arguments to the COLOR statement
-
- CONST CYAN% = 3
- CONST WHITE% = 7
-
- ' declare subprograms before they are used; subprogram names and
- ' parameters should match those in the subprograms
-
- DECLARE SUB GetShape (symbol$, choice%)
- DECLARE SUB PrintLine (char$)
- DECLARE SUB PrintRectangle (char$)
- DECLARE SUB PrintTriangle (char$)
-
- CLS
-
- ' call GetShape subprogram to get desired character and shape
-
- GetShape character$, shape% ' pass two arguments to GetShape
-
- PRINT
- PRINT
- COLOR CYAN%
-
- ' use CASE statement to call the requested subprogram
-
- SELECT CASE shape%
- CASE 1 ' if shape% = 1, display a triangle
- PrintTriangle character$
- CASE 2 ' if shape% = 2, display a rectangle
- PrintRectangle character$
- CASE 3 ' if shape% = 3, display a line
- PrintLine character$
- END SELECT
-
- COLOR WHITE%
-
- END
-
- SUB GetShape (symbol$, choice%)
-
- ' The GetShape subprogram prompts the user for a symbol and a shape
- ' and returns them to the main program in the symbol$ and choice%
- ' variables.
-
- PRINT "This program prints a collection of characters in the ";
- PRINT "shape you specify."
- PRINT
- INPUT "What character would you like to use: ", symbol$
- PRINT
- PRINT "What shape would you like to see:"
- PRINT
- PRINT " 1) Triangle"
- PRINT " 2) Rectangle"
- PRINT " 3) Line"
- PRINT
-
- DO ' prompt the user until choice% is in the right range
- INPUT "Shape (1, 2, or 3): ", choice%
- LOOP WHILE (choice% < 1) OR (choice% > 3)
-
- END SUB ' subprogram complete--return to the main program
-
- SUB PrintLine (char$)
-
- ' The PrintLine subprogram receives an argument from the main
- ' program and uses it to print a line 30 characters long.
-
- CONST LENGTH% = 30 ' set the length of the line at 30 characters
-
- FOR i% = 1 TO LENGTH% ' display the character 30 times
- PRINT char$; ' use semicolon to print them one after another
- NEXT i%
-
- PRINT
-
- END SUB
-
- SUB PrintRectangle (char$)
-
- ' The PrintRectangle subprogram receives an argument from the main
- ' program and uses it to print a rectangle 50 characters long by
- ' 7 characters high.
-
- CONST LENGTH% = 50 ' set length of rectangle at 50 rows
- CONST HEIGHT% = 7 ' set height of rectangle at 7 lines
-
- FOR i% = 1 TO HEIGHT% ' for each of the 7 rows in the rectangle,
- FOR j% = 1 TO LENGTH% ' display 50 characters one after another
- PRINT char$;
- NEXT j%
- PRINT ' print a carriage return after each row
- NEXT i%
-
- END SUB
-
- SUB PrintTriangle (char$)
-
- ' The PrintTriangle subprogram receives an argument from the main
- ' program and uses it to print an equilateral triangle. The Tab
- ' function moves the cursor to the correct column location.
-
- CONST ROWS% = 10 ' set the number of rows to 10
- left% = ROWS% ' use left% to build left side of triangle
- right% = ROWS% + 1 ' use right% to build right side of triangle
-
- FOR rowCount% = 1 TO ROWS% ' for each row in the triangle
- FOR i% = left% TO ROWS%
- PRINT TAB(i%); char$; ' display left side of row
- NEXT i%
-
- FOR i% = ROWS% + 1 TO right% - 1 ' display right side of row
- PRINT TAB(i%); char$;
- NEXT i%
-
- PRINT ' print carriage return at end of row
- left% = left% - 1 ' first character in next row will start one
- right% = right% + 1 ' space closer to left margin and extend
- NEXT rowCount% ' one space closer to the right margin
-
- END SUB
-
-